/*
 * @Author: 18970328563 2726167793@qq.com
 * @Date: 2023-03-27 22:29:20
 * @LastEditors: 18970328563 2726167793@qq.com
 * @LastEditTime: 2023-03-27 22:49:24
 * @FilePath: \vant_admin\src\http\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios';
import { showLoadingToast,closeToast } from 'vant';
//创建一个实例
const instance = axios.create({
    baseURL: 'http://backend-api-01.newbee.ltd/api/v1',
    timeout: 6000,
  });

let requestCount = 0 

  // 添加请求拦截器
  instance.interceptors.request.use( (config)=> {
    requestCount++
    if(requestCount == 1){
        showLoadingToast({
            message: '加载中...',
            forbidClick: true,
          });
    }
    return config;
  },(error)=> {
    return Promise.reject(error);
  });

// 添加响应拦截器
instance.interceptors.response.use( (response)=> {
    requestCount--
    if(requestCount==0){
        closeToast(true)
    }
    return response.data;
  },(error)=> {
 
    return Promise.reject(error);
  });

  export default instance